"use strict";

exports.__esModule = true;
exports.normalizeCoordsIfNeeded = normalizeCoordsIfNeeded;
var _number = require("../../helpers/number");
var _mixed = require("../../helpers/mixed");
/**
 * Normalizes the coordinates (clamps to nearest visible cell position within dataset range).
 *
 * @param {Core} hot The Handsontable instance.
 * @returns {function(Coords | undefined): Coords | null}
 */
function normalizeCoordsIfNeeded(hot) {
  return coords => {
    if (!coords) {
      return null;
    }
    const {
      rowIndexMapper,
      columnIndexMapper
    } = hot;
    if (rowIndexMapper.isHidden(coords.row) || columnIndexMapper.isHidden(coords.col)) {
      return null;
    }
    const mostTopStartCoords = (0, _mixed.getMostTopStartPosition)(hot);
    const mostBottomEndCoords = (0, _mixed.getMostBottomEndPosition)(hot);
    coords.row = (0, _number.clamp)(coords.row, mostTopStartCoords.row, mostBottomEndCoords.row);
    coords.col = (0, _number.clamp)(coords.col, mostTopStartCoords.col, mostBottomEndCoords.col);
    return coords;
  };
}